package com.cci.kangdao.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.IntegralOperationService;
import com.cci.kangdao.utilTool.ParameterTool;

/**
 * 积分操作
 * @author fengshuai
 *
 */
@Controller
public class IntegralOperationController {
	private Logger log = Logger.getLogger(this.getClass().getName());

	@Resource
	private IntegralOperationService integralOperationService;

	/**
	 * App用户获取积分日志接口
	 */
	@RequestMapping("/getIntegralLog.aspx")
	public ModelAndView getIntegralLog(HttpServletRequest request, HttpServletResponse response) {

		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return integralOperationService.getIntegralLog(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	/**
	 *App用户获取积分规则接口
	 */
	@RequestMapping("/getIntegralSetup.aspx")
	public ModelAndView getIntegralSetup(HttpServletRequest request, HttpServletResponse response) {
		
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return integralOperationService.getIntegralSetup(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	/**
	 *	App用户上传积分接口
	 */
	@RequestMapping("/uploadIntegral.aspx")
	public ModelAndView uploadIntegral(HttpServletRequest request, HttpServletResponse response) {
		
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return integralOperationService.uploadIntegral(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	/**
	 *App用户上传行为记录
	 */
	@RequestMapping("/uploadRecordLogs.aspx")
	public ModelAndView uploadRecordLogs(HttpServletRequest request, HttpServletResponse response) {
		
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return integralOperationService.uploadRecordLogs(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
}
